package com.ettractions.kiosk.utils
{
	import com.ettractions.kiosk.vo.BrochureVO;
	
	import mx.collections.ArrayList;
	
	public class ViewUtils
	{
		public static function generateListDataProvider(source:Vector.<BrochureVO>, itemCount:int = -1, firstItemIndex:int = -1, centerItemIndex:int = -1):ArrayList
		{
			var dataProvider:ArrayList = new ArrayList();
			var currentIndex:int;
			
			if (itemCount == -1)
				itemCount = source.length;
			
			if (centerItemIndex > -1)
				currentIndex = centerItemIndex - Math.floor(itemCount / 2);
			
			else
				currentIndex = firstItemIndex > -1
				             ? firstItemIndex
				             : 0;
			
			while (dataProvider.length < itemCount)
			{
				if (currentIndex < 0)
					dataProvider.addItem(source[source.length + currentIndex]);
				
				else
					dataProvider.addItem(source[currentIndex]);
				
				if (++currentIndex == source.length)
					currentIndex = 0;
			}
			
			return dataProvider;
		}
	}
}